package com.quanquan.management.repository;

import com.quanquan.management.entity.SysPermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @description:
 * @author:lihonglinag
 * @date:2019-03-21 11:35
 * @version:v 1.0.0
 */
public interface SysPermissionRepository extends JpaRepository<SysPermission,String> {

    @Query(value = "select p.* from oo_sys_permission p left join oo_sys_permission_role pr on pr.permission_id=p.id left join oo_sys_role_user ru on ru.role_id=pr.role_id where ru.user_id = ?1",nativeQuery=true)
    List<SysPermission> getPermissionByUserId(String userId);

    /**
     * 根据等级查询权限
     * @param level
     * @return
     */
    @Query(value = "select * from oo_sys_permission where level = ?1",nativeQuery = true)
    List<SysPermission> findBySysLevel(Integer level);

    @Query(value = "select * from oo_sys_permission where parent_id = ?1 and level = ?2",nativeQuery = true)
    List<SysPermission> findByParentIdAndLevel(String permissionId, Integer level);




}
